package com.hatricks.is.common.dto;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpStatus;
import cn.hutool.http.HttpUtil;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @packageName: com.hatricks.common.dto
 * @className: Response
 * @author: yanyuhui
 * @date: 2023/1/7 21:05
 * @description:
 */
@Data
@AllArgsConstructor
public class Response<T> {
    private Integer code;
    private String message;
    private T data;

    public static <T> Response<T> success(String message) {
        return new Response<T>(HttpStatus.HTTP_OK, message, null);
    }

    public static <T> Response<T> success(String message, T data) {
        return new Response<T>(HttpStatus.HTTP_OK, message, data);
    }

    public static <T> Response<T> failBad(String message) {
        return new Response<T>(HttpStatus.HTTP_BAD_REQUEST, message, null);
    }

    public static <T> Response<T> failBad(String message, Object... args) {
        return new Response<T>(HttpStatus.HTTP_BAD_REQUEST, StrUtil.format(message, args), null);
    }

    public static <T> Response<T> fail(String message) {
        return new Response<T>(HttpStatus.HTTP_INTERNAL_ERROR, message, null);
    }

    public static <T> Response<T> fail(String message, Object... args) {
        return new Response<T>(HttpStatus.HTTP_INTERNAL_ERROR, StrUtil.format(message, args), null);
    }

}
